{extend name="lib/common_list" /}
{block name="title"}成员列表{/block}
{block name="css"}{/block}
{block name="javascript"}
    <script type="text/javascript">
        function initRoleUserTable() {
            //先销毁表格
            $('#roleuser_tb').bootstrapTable('destroy');
            //初始化表格,动态从服务器加载数据
            $("#roleuser_tb").bootstrapTable({
                method: "Post",  //使用get请求到服务器获取数据
                url: "{:url('role/getroleuserlist')}?roleid={$roleid}", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: 20,  //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [20, 50],  //记录数可选列表
                search: false,  //是否启用查询
                sidePagination: "server", //表示服务端请求
                queryParamsType: "limit",
                contentType: "application/x-www-form-urlencoded",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        limit: params.limit,
                        offset: params.offset,
                        keyword: $("#keyword").val()                        
                    };
                    return param;
                },
                onLoadSuccess: function () {  //加载成功时执行

                },
                onLoadError: function () {  //加载失败时执行
                    layer.msg("加载数据失败", { time: 1500, icon: 2 });
                },
                rowStyle: function (row, index) {
                    var strclass = "";
                    if (row.IsDisable) {
                        strclass = 'danger';
                    }
                    else {
                        return {};
                    }
                    return { classes: strclass }
                }
            });
        }

        $(document).ready(function () {
            //调用函数，初始化表格
            initRoleUserTable();
            //当点击查询按钮的时候执行
            $("#search").bind("click", initRoleUserTable);
            $("#btnAdd").bind("click", add);
        });

        var layer_roleuseradd_index;
        function add() {
            layer_roleuseradd_index = layer.open({
                type: 2,
                title: "成员列表",
                shadeClose: false,
                shade: 0.6,
                skin: 'layui-layer-rim',
                area: ['100%', '100%'],
                //scrollbar: false,
                content: ["{:url('role/roleuseradd')}?roleid={$roleid}"]
            })
        }
        
        function operateFormatter(index, row) {
            if (row.id != 1) {
                return "<a href=\"javascript:Delete(" + row.userid + ");\"><i class=\"fa fa-times text-danger\"></i>删除</a>";
            }
        }

        function Delete(id) {
            layer.confirm('你确定要删除该成员吗？', {
                btn: ['是', '否'] //按钮
            }, function () {
                var load_index = layer.load(0, { shade: false });
                $.ajax({
                    type: "post",
                    url: "{:url('role/delroleuser')}?t=" + new Date(),
                    data: { Id: id },
                    dataType: "json",
                    success: function (result) {
                        layer.close(load_index);
                        if (result.code == 0) {
                            var ly = layer.alert('删除成功！', function () {
                                initRoleUserTable();
                                layer.close(ly);
                            });
                        } else {
                            layer.alert(result.msg);
                        }
                    },
                    error:function(xhr,textStatus){
                        layer.close(load_index);
                        layer.alert('服务器繁忙！');
                    }
                });
            });
        }

        var layer_roleuser_index;
        function Roleuser(id) {
            layer_roleuser_index = layer.open({
                type: 2,
                title: "成员列表",
                shadeClose: false,
                shade: 0.6,
                skin: 'layui-layer-rim',
                area: ['100%', '100%'],
                //scrollbar: false,
                content: ["{:url('role/roleuser')}"]
            })
        }
    </script>
{/block}

{block name="content"}
   <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>成员列表</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-2 m-b-xs">
                                <span>
                                    <button type="button" class="btn btn-primary btn-sm" id="btnAdd"><i class="glyphicon glyphicon-plus"></i> 新增</button>
                                </span>
                            </div>
                            <div class="col-sm-2 col-sm-offset-2">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <input type="text" placeholder="请输入成员名" class="input-sm form-control" id="keyword" name="keyword">
                                        <button type="button" class="btn btn-sm btn-primary" id="search">搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <table data-toggle="table" id="roleuser_tb" data-pagination="true">
                            <thead>
                                <tr>
                                    <th data-field="real_name" data-align="center">成员名称</th>                              
                                    <th data-align="center" data-formatter="operateFormatter">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
{/block} 
